inherited sprUsers: TsprUsers
  Left = 415
  Top = 216
  Caption = #1057#1087#1088#1072#1074#1086#1095#1085#1080#1082' '#1087#1086#1083#1100#1079#1086#1074#1072#1090#1077#1083#1077#1081
  Constraints.MinHeight = 600
  Constraints.MinWidth = 780
  PixelsPerInch = 96
  TextHeight = 13
  inherited ToolBar1: TToolBar
    inherited ToolButton7: TToolButton
      Visible = False
    end
  end
  inherited Panel2: TPanel
    Top = 71
    Height = 483
    inherited PageControl1: TPageControl
      Height = 483
      ActivePage = tsForm
      inherited tsTab: TTabSheet
        inherited GroupBox3: TGroupBox
          Height = 455
          inherited dbgRefer: TDBGridEh
            Height = 438
            Columns = <
              item
                EditButtons = <>
                FieldName = 'ID'
                Footers = <>
              end
              item
                EditButtons = <>
                FieldName = 'GROUPCODE'
                Footers = <>
                Visible = False
              end
              item
                EditButtons = <>
                FieldName = 'GROUPNAME'
                Footers = <>
                Visible = False
              end
              item
                EditButtons = <>
                FieldName = 'SURNAME'
                Footers = <>
                Width = 133
              end
              item
                EditButtons = <>
                FieldName = 'FIRSTNAME'
                Footers = <>
                Width = 72
              end
              item
                EditButtons = <>
                FieldName = 'LASTNAME'
                Footers = <>
                Width = 76
              end
              item
                EditButtons = <>
                FieldName = 'USERNAME'
                Footers = <>
                Width = 78
              end
              item
                EditButtons = <>
                FieldName = 'NAMEMAG'
                Footers = <>
                Width = 91
              end
              item
                Checkboxes = True
                EditButtons = <>
                FieldName = 'ACCESS'
                Footers = <>
              end
              item
                EditButtons = <>
                FieldName = 'CREATEDATE'
                Footers = <>
              end
              item
                EditButtons = <>
                FieldName = 'MODIFYDATE'
                Footers = <>
              end>
          end
        end
      end
      inherited tsForm: TTabSheet
        OnShow = tsFormShow
        inherited GroupBox2: TGroupBox
          Top = 0
          Width = 784
          Height = 455
          Align = alClient
          inherited pnlButtons: TPanel
            Top = 422
            Width = 780
            TabOrder = 1
            inherited SpeedButton1: TSpeedButton
              Left = 581
            end
            inherited SpeedButton2: TSpeedButton
              Left = 683
            end
          end
          object Panel1: TPanel
            Left = 2
            Top = 15
            Width = 384
            Height = 407
            Align = alClient
            BevelOuter = bvNone
            TabOrder = 0
            object Label1: TLabel
              Left = 0
              Top = 2
              Width = 90
              Height = 13
              Alignment = taRightJustify
              AutoSize = False
              Caption = #1048#1044
            end
            object Label2: TLabel
              Left = 0
              Top = 26
              Width = 90
              Height = 13
              Alignment = taRightJustify
              AutoSize = False
              Caption = #1060#1072#1084#1080#1083#1080#1103
            end
            object Label3: TLabel
              Left = 0
              Top = 50
              Width = 90
              Height = 13
              Alignment = taRightJustify
              AutoSize = False
              Caption = #1048#1084#1103
            end
            object Label4: TLabel
              Left = 0
              Top = 74
              Width = 90
              Height = 13
              Alignment = taRightJustify
              AutoSize = False
              Caption = #1054#1090#1095#1077#1089#1090#1074#1086
            end
            object Label5: TLabel
              Left = 0
              Top = 121
              Width = 90
              Height = 13
              Alignment = taRightJustify
              AutoSize = False
              Caption = #1044#1086#1089#1090#1091#1087
            end
            object Label8: TLabel
              Left = 0
              Top = 98
              Width = 90
              Height = 13
              Alignment = taRightJustify
              AutoSize = False
              Caption = #1056#1086#1083#1100
            end
            object Label6: TLabel
              Left = 0
              Top = 137
              Width = 90
              Height = 27
              Alignment = taRightJustify
              AutoSize = False
              Caption = #1044#1086#1074#1077#1088#1077#1085#1085#1086#1089#1090#1100' '#1074' '#1088#1086#1076'. '#1087#1072#1076#1077#1078#1077
              WordWrap = True
            end
            object Label7: TLabel
              Left = 0
              Top = 168
              Width = 90
              Height = 39
              Alignment = taRightJustify
              AutoSize = False
              Caption = #1060#1048#1054' '#1087#1086#1083#1100#1079#1086#1074#1072#1090#1077#1083#1103' '#1074' '#1088#1086#1076'. '#1087#1072#1076#1077#1078#1077
              WordWrap = True
            end
            object dbeID: TDBEditEh
              Left = 99
              Top = 0
              Width = 57
              Height = 19
              AlwaysShowBorder = True
              DataField = 'ID'
              DataSource = dscRefer
              EditButtons = <>
              Enabled = False
              Flat = True
              ParentShowHint = False
              ReadOnly = True
              ShowHint = True
              TabOrder = 0
              Visible = True
            end
            object dbeLname: TDBEditEh
              Left = 99
              Top = 24
              Width = 274
              Height = 19
              AlwaysShowBorder = True
              DataField = 'SURNAME'
              DataSource = dscRefer
              EditButtons = <>
              Flat = True
              ParentShowHint = False
              ShowHint = True
              TabOrder = 1
              Visible = True
            end
            object dbeFname: TDBEditEh
              Left = 99
              Top = 48
              Width = 274
              Height = 19
              AlwaysShowBorder = True
              DataField = 'FIRSTNAME'
              DataSource = dscRefer
              EditButtons = <>
              Flat = True
              ParentShowHint = False
              ShowHint = True
              TabOrder = 2
              Visible = True
            end
            object dbeSname: TDBEditEh
              Left = 99
              Top = 72
              Width = 274
              Height = 19
              AlwaysShowBorder = True
              DataField = 'LASTNAME'
              DataSource = dscRefer
              EditButtons = <>
              Flat = True
              ParentShowHint = False
              ShowHint = True
              TabOrder = 3
              Visible = True
            end
            object cbAccess: TDBCheckBoxEh
              Left = 99
              Top = 120
              Width = 25
              Height = 17
              AlwaysShowBorder = True
              Checked = True
              DataField = 'ACCESS'
              DataSource = dscRefer
              Flat = True
              TabOrder = 5
              ValueChecked = '1'
              ValueUnchecked = '0'
              OnClick = cbAccessClick
            end
            object lcbRole: TDBLookupComboboxEh
              Left = 99
              Top = 96
              Width = 274
              Height = 19
              AlwaysShowBorder = True
              DataField = 'GROUPCODE'
              DataSource = dscRefer
              EditButtons = <>
              Flat = True
              KeyField = 'GROUPCODE'
              ListField = 'GROUPNAME'
              ListSource = dscGroups
              ParentShowHint = False
              ShowHint = True
              TabOrder = 4
              Visible = True
            end
            object gbLogin: TGroupBox
              Left = 0
              Top = 214
              Width = 384
              Height = 193
              Align = alBottom
              Caption = ' '#1051#1086#1075#1080#1085' '
              TabOrder = 7
              object Label11: TLabel
                Left = 15
                Top = 18
                Width = 120
                Height = 13
                Alignment = taRightJustify
                AutoSize = False
                Caption = #1051#1086#1075#1080#1085
              end
              object Label10: TLabel
                Left = 15
                Top = 42
                Width = 120
                Height = 13
                Alignment = taRightJustify
                AutoSize = False
                Caption = #1055#1072#1088#1086#1083#1100
              end
              object Label12: TLabel
                Left = 15
                Top = 66
                Width = 120
                Height = 13
                Alignment = taRightJustify
                AutoSize = False
                Caption = #1055#1086#1076#1090#1074#1077#1088#1078#1076#1077#1085#1080#1077' '#1087#1072#1088#1086#1083#1103
              end
              object dbeLogin: TDBEditEh
                Left = 142
                Top = 16
                Width = 121
                Height = 19
                AlwaysShowBorder = True
                CharCase = ecUpperCase
                DataField = 'USERNAME'
                DataSource = dscRefer
                EditButtons = <>
                Flat = True
                ParentShowHint = False
                ShowHint = True
                TabOrder = 0
                Visible = True
              end
              object ePass1: TEdit
                Left = 142
                Top = 40
                Width = 121
                Height = 19
                BevelInner = bvLowered
                BevelKind = bkSoft
                BevelOuter = bvNone
                BorderStyle = bsNone
                PasswordChar = '*'
                TabOrder = 1
              end
              object ePass2: TEdit
                Left = 142
                Top = 64
                Width = 121
                Height = 19
                BevelInner = bvLowered
                BevelKind = bkSoft
                BevelOuter = bvNone
                BorderStyle = bsNone
                PasswordChar = '*'
                TabOrder = 2
              end
            end
            object dbeDoverennost: TDBEditEh
              Left = 99
              Top = 141
              Width = 274
              Height = 19
              AlwaysShowBorder = True
              DataField = 'DOVERENNOST'
              DataSource = dscRefer
              EditButtons = <>
              Flat = True
              ParentShowHint = False
              ShowHint = True
              TabOrder = 6
              Visible = True
            end
            object dbeFULLNAME_GEN_CASE: TDBEditEh
              Left = 99
              Top = 173
              Width = 274
              Height = 19
              AlwaysShowBorder = True
              DataField = 'FULLNAME_GEN_CASE'
              DataSource = dscRefer
              EditButtons = <>
              Flat = True
              ParentShowHint = False
              ShowHint = True
              TabOrder = 8
              Visible = True
            end
          end
          object dbgOrgs: TDBGridEh
            Left = 386
            Top = 15
            Width = 396
            Height = 407
            Align = alRight
            AllowedOperations = [alopUpdateEh]
            Anchors = [akLeft, akTop, akRight, akBottom]
            ColumnDefValues.Title.TitleButton = True
            DataGrouping.GroupLevels = <>
            DataSource = dscUser2Org
            Flat = True
            FooterColor = clWindow
            FooterFont.Charset = DEFAULT_CHARSET
            FooterFont.Color = clWindowText
            FooterFont.Height = -11
            FooterFont.Name = 'MS Sans Serif'
            FooterFont.Style = []
            OddRowColor = clMoneyGreen
            Options = [dgTitles, dgColumnResize, dgColLines, dgRowLines, dgTabs, dgRowSelect, dgConfirmDelete]
            OptionsEh = [dghFixed3D, dghHighlightFocus, dghClearSelection, dghAutoSortMarking, dghMultiSortMarking, dghDblClickOptimizeColWidth, dghDialogFind, dghColumnResize, dghColumnMove]
            RowDetailPanel.Color = clBtnFace
            SortLocal = True
            TabOrder = 2
            TitleFont.Charset = DEFAULT_CHARSET
            TitleFont.Color = clWindowText
            TitleFont.Height = -11
            TitleFont.Name = 'MS Sans Serif'
            TitleFont.Style = []
            UseMultiTitle = True
            VTitleMargin = 5
            OnDblClick = aEditExecute
            OnSortMarkingChanged = dbgReferSortMarkingChanged
            Columns = <
              item
                Color = clInactiveCaptionText
                EditButtons = <>
                FieldName = 'NAME'
                Footers = <>
                ReadOnly = True
                Width = 275
              end
              item
                Checkboxes = True
                EditButtons = <>
                FieldName = 'ACCESS'
                Footers = <>
                OnAfterUpdateData = dbgOrgsColumns1AfterUpdateData
              end>
            object RowDetailData: TRowDetailPanelControlEh
            end
          end
        end
      end
    end
  end
  inherited GroupBox1: TGroupBox
    Height = 46
    object lcbOrgs: TDBLookupComboboxEh
      Left = 16
      Top = 16
      Width = 401
      Height = 19
      AlwaysShowBorder = True
      DropDownBox.Sizable = True
      DropDownBox.SpecRow.CellsText = #1074#1089#1077' '#1086#1088#1075#1072#1085#1080#1079#1072#1094#1080#1080
      DropDownBox.SpecRow.Visible = True
      EditButtons = <>
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      Flat = True
      KeyField = 'ID'
      ListField = 'NAME'
      ListSource = dscOrgs
      ParentFont = False
      ParentShowHint = False
      ShowHint = True
      TabOrder = 0
      Visible = True
      OnKeyValueChanged = lcbOrgsKeyValueChanged
    end
  end
  inherited shblActionList: TActionList
    object aSave: TAction
      Caption = #1057#1086#1093#1088#1072#1085#1080#1090#1100
      Hint = #1057#1086#1093#1088#1072#1085#1080#1090#1100' '#1080#1079#1084#1077#1085#1077#1085#1080#1103' '#1073#1077#1079' '#1089#1084#1077#1085#1099' '#1087#1072#1088#1086#1083#1103
      ImageIndex = 15
      OnExecute = aSaveExecute
    end
  end
  inherited dsRefer: TpFIBDataSet
    UpdateSQL.Strings = (
      'UPDATE USERNAME'
      'SET '
      '    GROUPCODE = :GROUPCODE,'
      '    ACCESS = :ACCESS,'
      '    SURNAME = :SURNAME,'
      '    FIRSTNAME = :FIRSTNAME,'
      '    LASTNAME = :LASTNAME,'
      '    DOVERENNOST = :DOVERENNOST,'
      '    FULLNAME_GEN_CASE = :FULLNAME_GEN_CASE'
      'WHERE'
      '    ID = :OLD_ID'
      '    ')
    DeleteSQL.Strings = (
      'DELETE FROM'
      '    USERNAME'
      'WHERE'
      '        ID = :OLD_ID')
    InsertSQL.Strings = (
      'INSERT INTO USERNAME('
      '    ID,'
      '    GROUPCODE,'
      '    ACCESS,'
      '    SURNAME,'
      '    FIRSTNAME,'
      '    LASTNAME,'
      '    USERNAME,'
      '    NAMEMAG,'
      '    DOVERENNOST,'
      '    FULLNAME_GEN_CASE'
      ')'
      'VALUES('
      '    :ID,'
      '    :GROUPCODE,'
      '    :ACCESS,'
      '    :SURNAME,'
      '    :FIRSTNAME,'
      '    :LASTNAME,'
      '    :USERNAME,'
      '    :USERNAME,'
      '    :DOVERENNOST,'
      '    :FULLNAME_GEN_CASE'
      ')'
      'returning id')
    RefreshSQL.Strings = (
      'SELECT'
      '    u.ID,'
      '    u.GROUPCODE,'
      
        '    (select ug.groupname from usergroup ug where ug.groupcode = ' +
        'u.GROUPCODE) as groupname,'
      '    coalesce(u.ACCESS, 0) as ACCESS,'
      '    u.SURNAME,'
      '    u.FIRSTNAME,'
      '    u.LASTNAME,'
      '    u.USERNAME,'
      '    u.NAMEMAG,'
      '    u.DOVERENNOST,'
      '    u.CREATEDATE,'
      '    u.MODIFYDATE,'
      '    u.fullname_gen_case'
      'FROM'
      '    USERNAME u, user2org u2'
      'where u.id = u2.user_id'
      '  and u2.org_id = :orgcode'
      '  and U.ID = :OLD_ID'
      '    ')
    SelectSQL.Strings = (
      'SELECT'
      '    u.ID,'
      '    u.GROUPCODE,'
      
        '    (select ug.groupname from usergroup ug where ug.groupcode = ' +
        'u.GROUPCODE) as groupname,'
      '    coalesce(u.ACCESS, 0) as ACCESS,'
      '    u.SURNAME,'
      '    u.FIRSTNAME,'
      '    u.LASTNAME,'
      '    u.USERNAME,'
      '    u.NAMEMAG,'
      '    u.DOVERENNOST,'
      '    u.CREATEDATE,'
      '    u.MODIFYDATE,'
      '    u.fullname_gen_case'
      'FROM'
      '    USERNAME u'
      'where cast(:orgcode as integer) is null'
      '   or exists(select 1 from user2org u2 '
      '        where u.id = u2.user_id '
      '          and u2.org_id = :orgcode)')
    UpdateTransaction = trRefer
    Left = 44
    Top = 208
    object dsReferID: TFIBIntegerField
      DisplayLabel = #1048#1044
      FieldName = 'ID'
    end
    object dsReferGROUPCODE: TFIBIntegerField
      FieldName = 'GROUPCODE'
    end
    object dsReferGROUPNAME: TFIBStringField
      FieldName = 'GROUPNAME'
      Size = 25
      EmptyStrToNull = True
    end
    object dsReferACCESS: TFIBSmallIntField
      DisplayLabel = #1044#1086#1089#1090#1091#1087
      FieldName = 'ACCESS'
    end
    object dsReferSURNAME: TFIBStringField
      DisplayLabel = #1060#1072#1084#1080#1083#1080#1103
      FieldName = 'SURNAME'
      Size = 35
      EmptyStrToNull = True
    end
    object dsReferFIRSTNAME: TFIBStringField
      DisplayLabel = #1048#1084#1103
      FieldName = 'FIRSTNAME'
      Size = 30
      EmptyStrToNull = True
    end
    object dsReferLASTNAME: TFIBStringField
      DisplayLabel = #1054#1090#1095#1077#1089#1090#1074#1086
      FieldName = 'LASTNAME'
      Size = 35
      EmptyStrToNull = True
    end
    object dsReferUSERNAME: TFIBStringField
      DisplayLabel = #1051#1086#1075#1080#1085
      FieldName = 'USERNAME'
      Size = 60
      EmptyStrToNull = True
    end
    object dsReferNAMEMAG: TFIBStringField
      DisplayLabel = #1048#1084#1103' '#1074' '#1089#1080#1089#1090#1077#1084#1077
      FieldName = 'NAMEMAG'
      Size = 60
      EmptyStrToNull = True
    end
    object dsReferCREATEDATE: TFIBDateField
      DefaultExpression = 'current_date'
      DisplayLabel = #1057#1086#1079#1076#1072#1085
      FieldName = 'CREATEDATE'
      DisplayFormat = 'dd.mm.yyyy'
    end
    object dsReferMODIFYDATE: TFIBDateField
      DisplayLabel = #1048#1079#1084#1077#1085#1077#1085
      FieldName = 'MODIFYDATE'
      DisplayFormat = 'dd.mm.yyyy'
    end
    object dsReferDOVERENNOST: TFIBStringField
      FieldName = 'DOVERENNOST'
      Size = 120
      EmptyStrToNull = True
    end
    object dsReferFULLNAME_GEN_CASE: TFIBStringField
      FieldName = 'FULLNAME_GEN_CASE'
      Size = 120
      EmptyStrToNull = True
    end
  end
  inherited dscRefer: TDataSource
    Left = 76
    Top = 200
  end
  inherited trRefer: TpFIBTransaction
    Left = 16
    Top = 204
  end
  inherited PropStorage: TPropStorageEh
    Top = 88
  end
  object dsOrgs: TpFIBDataSet
    SelectSQL.Strings = (
      'select id, name'
      'from userorg '
      'where access = 1'
      'order by name')
    Transaction = trLists
    Database = MAINDM.pMainDatabase
    Left = 406
    Top = 187
    object dsOrgsID: TFIBIntegerField
      FieldName = 'ID'
    end
    object dsOrgsNAME: TFIBStringField
      FieldName = 'NAME'
      ReadOnly = True
      Size = 60
      EmptyStrToNull = True
    end
  end
  object dscOrgs: TDataSource
    DataSet = dsOrgs
    Left = 438
    Top = 187
  end
  object pSecurityService: TpFIBSecurityService
    ServerName = '172.16.0.100'
    Protocol = TCP
    Params.Strings = (
      'user_name=plasmorf'
      'password=ytdbyyjcnm'
      'sql_role_name=rdb$admin')
    LoginPrompt = False
    SecurityAction = ActionDisplayUser
    UserName = 'test'
    UserID = 0
    GroupID = 0
    Left = 478
    Top = 190
  end
  object dsGroups: TpFIBDataSet
    SelectSQL.Strings = (
      'select ug.groupcode, ug.groupname, ug.rolename from usergroup ug')
    Transaction = trLists
    Database = MAINDM.pMainDatabase
    Left = 406
    Top = 267
    object dsGroupsGROUPCODE: TFIBSmallIntField
      FieldName = 'GROUPCODE'
    end
    object dsGroupsGROUPNAME: TFIBStringField
      FieldName = 'GROUPNAME'
      Size = 25
      EmptyStrToNull = True
    end
    object dsGroupsROLENAME: TFIBStringField
      FieldName = 'ROLENAME'
      Size = 30
      EmptyStrToNull = True
    end
  end
  object dscGroups: TDataSource
    DataSet = dsGroups
    Left = 438
    Top = 267
  end
  object trRole: TpFIBTransaction
    DefaultDatabase = MAINDM.pMainDatabase
    TimeoutAction = TARollback
    Left = 440
    Top = 303
  end
  object qAddRole: TpFIBQuery
    Transaction = trRole
    Database = MAINDM.pMainDatabase
    SQL.Strings = (
      'GRANT @@rolename@ TO @@namemag@; '
      '/*'
      'INSERT INTO RDB$USER_PRIVILEGES ('
      ' RDB$USER, '
      ' RDB$GRANTOR, '
      ' RDB$PRIVILEGE, '
      ' RDB$GRANT_OPTION, '
      ' RDB$RELATION_NAME, '
      ' RDB$FIELD_NAME, '
      ' RDB$USER_TYPE, '
      ' RDB$OBJECT_TYPE) '
      'VALUES ('
      ' :namemag, '
      ' '#39'SYSDBA'#39', '
      ' '#39'M'#39', '
      ' NULL, '
      ' :rolename, '
      ' NULL, '
      ' 8, '
      ' 13);'
      '*/')
    Left = 410
    Top = 303
    qoAutoCommit = True
    qoStartTransaction = True
  end
  object qDelRole: TpFIBQuery
    Transaction = trRole
    Database = MAINDM.pMainDatabase
    SQL.Strings = (
      'DELETE from RDB$USER_PRIVILEGES '
      'where RDB$USER = :namemag'
      'and RDB$RELATION_NAME <> '#39'GRAD_REPORT'#39)
    Left = 410
    Top = 333
    qoAutoCommit = True
    qoStartTransaction = True
  end
  object dsUser2Org: TpFIBDataSet
    UpdateSQL.Strings = (
      'execute block '
      ' (user_id d_int = :user_id,'
      '  org_id d_int = :id,'
      '  access d_sint = :access'
      ')'
      'as '
      'begin'
      '  if (access = 1) then'
      '    update or insert into user2org (user_id, org_id) '
      '      values (:user_id, :org_id)'
      '      matching (user_id, org_id);'
      '  else'
      '    delete from user2org'
      '      where user_id = :user_id '
      '        and org_id = :org_id;'
      'end')
    SelectSQL.Strings = (
      'select u.id, u.name, '
      
        '    iif(exists (select 1 from user2org u2 where u2.user_id = un.' +
        'id and u2.org_id = u.id), 1, 0) as access,'
      '    un.id as user_id'
      'from userorg u'
      'full outer join username un on un.id = :puser_id'
      'where u.access = 1'
      'order by iif (u.id = :porg_id, 0, 1), u.name')
    BeforeOpen = dsUser2OrgBeforeOpen
    AllowedUpdateKinds = [ukModify]
    Transaction = trLists
    Database = MAINDM.pMainDatabase
    UpdateTransaction = trRefer
    Left = 622
    Top = 131
    object dsUser2OrgID: TFIBIntegerField
      FieldName = 'ID'
    end
    object dsUser2OrgACCESS: TFIBIntegerField
      DisplayLabel = #1044#1086#1089#1090#1091#1087
      DisplayWidth = 7
      FieldName = 'ACCESS'
    end
    object dsUser2OrgNAME: TFIBStringField
      DisplayLabel = #1054#1075#1088#1072#1085#1080#1079#1072#1094#1080#1103
      DisplayWidth = 30
      FieldName = 'NAME'
      Size = 60
      EmptyStrToNull = True
    end
    object dsUser2OrgUSER_ID: TFIBIntegerField
      FieldName = 'USER_ID'
    end
  end
  object dscUser2Org: TDataSource
    DataSet = dsUser2Org
    Left = 654
    Top = 131
  end
end
